package master;

/**
 * Excel表列序号
 *
 * @author chenyw
 * @date 2022/8/1 10:18
 */
public class M171titleToNumber {
    public static void main(String[] args) {
        int ab = new M171titleToNumber().titleToNumber("AB");
        System.out.println(ab);
    }
    public int titleToNumber(String columnTitle) {
        int sum = 0;
        for (int i = columnTitle.length() - 1; i >= 0; i--) {
            int a = columnTitle.charAt(i) - 'A' + 1;
            a = (int) (a * Math.pow(26, columnTitle.length() - i - 1));
            sum += a;
        }
        return sum;
    }
}
